/******************************************************************************
*  COPYRIGHT MorningCore CO.,LTD
******************************************************************************/

/*****************************************************************
* FileName::    SRP_PRACH_FE.c
* version::     V1.0.0
* Purpose:      Front End Symbol Rate Processing of PRACH
* Authors:      shanshan, 2022-11-14
* Notes:        None
******************************************************************/

/******************************************************************************
*  HISTORY OF CHANGES
*   <Date>          <Author>        <Version>       <DESCRIPTION>
*   2022-11-14      shanshan		V1.0.0          original
******************************************************************************/

/******************************************************************************
*  INCLUDE FILES
******************************************************************************/
#include "ue_tx_prach_fe_fix.h"
/*----------- function definition-----------------------------------*/
/*****************************************************************************
* Function: SRP_PRACH_FE()
* Purpose:  This function performs Front End Symbol Rate Processing of PRACH.
*
* Relation:
Calls       : PRACH_CS() PRACH_DFT() PRACH_REMapper()
Called by   : None
* Params:
*   <Name>                  <Type>      <In/Out>    <Description>
*   PRACH_Root_ZC_Seq[839]  cmplx_frN   In          input ZC Root sequence
*   PRACH_CyclicShiftParam  int         In          Cv value for cyclic shift
*   Shift0[11]              int8        In          1st FFT shift flag
*   Shift1[11]              int8        In          2nd FFT shift flag
*   BitWidth                int8        In          Processing bit width
*   SRP_PRACH_FE_Op[2048]   cmplx_frN   Out         output of SRP_PRACH_FE

  * Return:  void
  * Note:    None
*******************************************************************************/
void SRP_PRACH_FE_fix
(
    cmplx_frN   PRACH_Root_ZC_Seq[839], // Root seq from ZCRootSeqGen
    stULParamTable *SimParam,
    int         BitLength,               // processing bit width
    cmplx_frN   SRP_PRACH_FE_Op[4096]   // output of SRP_PRACH_FE
)
{
    // var declaration
    cmplx_frN  PRACH_CZT_Op[839]; // CZT output sequence
    int    PRACH_DFT_Shift = 0; // 839 - 5, 139 - 4
    char   cFileAddr[256] = {0};

    ///////////// SRP FE start /////////////////////
    // prime point DFT using chirp-Z transforming
    ZCDFT_fix(
        SimParam,
        BitLength,
        PRACH_DFT_Shift,
		PRACH_Root_ZC_Seq, // input sequence data
        PRACH_CZT_Op     // output
    );

#if UE_TX_PRINTFLAG
	sprintf_s(cFileAddr, "Result/PRACHTestData/%d/PRACH_DFT_Out.dat", CASEIDX_PRINT);
	vFilePrintDataFixpQI(cFileAddr, &PRACH_CZT_Op[0], SimParam->L_RA, BitLength);
#else
    sprintf_s(cFileAddr, "Result/PRACHTestData/%d/PRACH_DFT_Out.dat", CASEIDX_PRINT);
	vFilePrintData_Fxp2Flt(cFileAddr, &PRACH_CZT_Op[0], SimParam->L_RA, SimParam->PRACH_Scale);
#endif

    // PRACH sub-carriers mapping
    PRACH_REMapper_fix(
        PRACH_CZT_Op,      // frequency data input
        BitLength,
        SimParam,
        SRP_PRACH_FE_Op    // output of SRP_PRACH_FE
    );

#if UE_TX_PRINTFLAG
	sprintf_s(cFileAddr, "Result/PRACHTestData/%d/PrachReMapper_2.dat", CASEIDX_PRINT);
    vFilePrintDataFixpQI(cFileAddr, &SRP_PRACH_FE_Op[0], SimParam->RA_IFFT_Size, BitLength);
#else
    sprintf_s(cFileAddr, "Result/PRACHTestData/%d/SRP_PRACH_FE_Op.dat", CASEIDX_PRINT);
	vFilePrintData_Fxp2Flt(cFileAddr, &SRP_PRACH_FE_Op[0], SimParam->RA_IFFT_Size, SimParam->PRACH_Scale);
#endif

    /////////////// SRP FE end ///////////////////
}




